using Microsoft.AspNetCore.Mvc;
using Services.Identity.Domain;
using Services.Identity.WebApi.Request.Login;
using Services.Initial.PublicProject.PublicClass.OutPutModels;
using Services.Initial.PublicProject.PublicMethods;

namespace Services.Identity.WebApi.Controllers;
[ApiController]
[Route("[controller]/[action]")]
public class LoginController(IDomainService domainService, ILogger<LoginController> logger) : ControllerBase
{
    private readonly IDomainService domainService = domainService;
    private readonly ILogger<LoginController> logger = logger;

    [HttpPost]
    public async Task<OutputModel<string>> LoginByUserName(LoginByUserNameRequest request)
    {
        var (_, token) = await this.domainService.LoginByUserNameAsync(request.UserName, request.Password);
        return OutPutMethod<string>.Success(data: token!, message: "登录成功");
    }
    [HttpPost]
    public async Task<OutputModel<string>> LoginByUserPhone(LoginByUserPhoneRequest request)
    {
        var (_, token) = await this.domainService.LoginByUserPhoneAsync(request.UserPhone, request.Password);
        return OutPutMethod<string>.Success(data: token!, message: "登录成功");
    }
}